package com.logistics.map.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.logistics.map.entity.domain.MapRouteNodes;
import com.logistics.map.entity.model.MapComponentsRow;
import com.logistics.map.entity.model.MapRouteNodesRow;
import com.logistics.map.entity.model.MapRouteNodesSave;
import com.logistics.map.mapper.MapRouteNodesMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MapRouteNodesService extends ServiceImpl<MapRouteNodesMapper, MapRouteNodes> {

    /**
     * 保存边
     * @param save
     */
    public void save(MapRouteNodesSave save){
        this.save(MapRouteNodes.build(save));
    }

    /**
     * 根据code删除
     * @param codes
     */
    public void deleteByRouteCode(List<String> codes){
        this.remove(new LambdaQueryWrapper<MapRouteNodes>().in(MapRouteNodes::getRouteCode, codes));
    }

    /**
     * 根据code查找点位
     * @param codes
     * @return
     */
    public List<MapComponentsRow> listByCode(List<String> codes){
        return this.list(new LambdaQueryWrapper<MapRouteNodes>().
                in(MapRouteNodes::getRouteCode, codes)).stream().map(e -> MapComponentsRow.build(e))
                .collect(Collectors.toList());
    }
}
